<template>
  <div class="v-container g-white-space">
    <v-header title="平安银行洗车服务">
      <div class="personal" @click="pageTo('personal')">
        <!-- <span class="h5-iconfont icon-user" @click="pageTo('personal')"></span> -->
        <img src="@/assets/images/icon_grzx.png" width="24" alt="个人中心">
      </div>
    </v-header>
    <div class="v-main">
      <div>
        <img src="@/assets/images/sy_banner.jpg" width="100%" alt="首页banner">
      </div>
      <div class="button-box">
        <mt-button type="primary" class="my-button hot-button round" @click="washCar">我要洗车</mt-button>
        <mt-button class="my-button round" @click="pageTo('point')">网点查询</mt-button>
        <mt-button class="my-button round" @click="pageTo('order')">我的订单</mt-button>
      </div>
      <div class="index-sysm"><img src="@/assets/images/index_sysm.png" width="100%" alt="首页流程"></div>
    </div>
  </div>
</template>

<script>
import vHeader from '@/components/Header.vue';
import { Resource } from '@/services/resource';
// import Cookies from 'js-cookie';
import LocalStorage from '@/services/storage';
import { MessageBox } from 'mint-ui';

const BMap = window.BMap;

export default {
  name: 'home',
  components: {
    vHeader
  },
  props: {
    title: {
      type: String,
      default: '标题'
    }
  },
  data() {
    return {
      msg: 'Footera',
      show: true
    };
  },
  mounted() {
    this.gps();
    this.sendType();
    this.autoLogin();
    let time = new Date();
    if (time > new Date('2019/6/30 23:59:59')) {
      MessageBox.alert('活动已结束，谢谢参与');
    }
    //i am master
  },
  methods: {
    // 免登录
    autoLogin() {
      let token = LocalStorage.getLocalStorage('tokenPAPTXC');
      if (token) {
        Resource.login.post({}, { token: token }).then(res => {
          console.log(res);
        });
      }
    },
    // 地理定位
    gps() {
      const that = this;
      if (sessionStorage.longitude == undefined) {
        if (navigator.geolocation) {
          this.$store.dispatch('openLoading');
          var geolocation = new BMap.Geolocation();
          var geoc = new BMap.Geocoder();
          geolocation.getCurrentPosition(
            function(r) {
              that.$nextTick(() => {
                that.$store.dispatch('closeLoading');
              });
              // eslint-disable-next-line
              if (this.getStatus() == BMAP_STATUS_SUCCESS) {
                geoc.getLocation(r.point, function(rs) {
                  var addComp = rs.addressComponents;
                  console.info(rs);
                  sessionStorage.longitude = rs.point.lng; // 经度
                  sessionStorage.latitude = rs.point.lat; // 纬度
                  sessionStorage.gps = addComp.city; // 城市
                  sessionStorage.myAddress = addComp.province + addComp.city + addComp.district + addComp.street + addComp.streetNumber;
                });
              } else {
                this.$message.error('failed' + this.getStatus());
              }
            },
            {
              enableHighAccuracy: true
            }
          );
        } else {
          this.$message.error('该浏览器不支持地理定位。');
        }
      }
    },
    // 传递type
    sendType() {
      Resource.addressType.post({}, { type: sessionStorage.type }).then(res => {
        console.log(res);
      });
    },
    // 跳转页面
    pageTo(name) {
      console.log(name);
      this.$router.push(name);
    },
    // 我要洗车
    washCar() {
      let time = new Date();
      if (time > new Date('2019/6/30 23:59:59')) {
        return MessageBox.alert('活动已结束，谢谢参与');
      }
      this.pageTo('activity');
    }
  }
};
</script>

<style lang="less" scoped>
@import url('./home.less');
</style>


